﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TimKenSite.Master" AutoEventWireup="true"
    CodeBehind="ProductInfo.aspx.cs" Inherits="TimKen.Web.ProductInfo" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Title" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="body" runat="server">
    <form runat="server">
    <script type="text/javascript">
            $(document).ready(function () {
                $(".nav_li:eq(2)").children("a").addClass("navon"); //导航，当前栏目高亮	
                $(".left_nav ul li:eq(0)").children("a").addClass("left_navon"); //左侧导航，当前栏目高亮	
                $(".help_box_top li").click(function () {
                    var cpid = $(this).attr("id");
                    $(this).addClass("help_box_topon").siblings().removeClass("help_box_topon");
                    $("#s" + cpid).show().siblings().hide();
                });
                $(".product_cpxx ul").each(function () {
                    $(this).children("p:even").addClass("product_cpxxon");
                });
            });
            window.onload = function () { for (var ii = 0; ii < document.links.length; ii++) document.links[ii].onfocus = function () { this.blur() } }


//        $.ajax({
//            url: '/Ashx/TypeOption.ashx?ProductID=<%=ProductID%>',
//            type: 'GET',
//            timeout: 8000,
//            cache: false,
//            error: function() {
//                alert('<%=GetLangString("LoadOptionError")%>');
//            },
//            success: function(html) {
//                //document.getElementById("tdAttributeList").innerHTML = html;
//            }
//        });
        var pageIndex = 1
        var pageCount = 0;

        $(function() {
            GetPageCount(); //取得分页总数
            pageCount = parseInt($("#pagecount").val()); //分页总数放到变量pageCount里
            $("#load").hide(); //隐藏loading提示
            $("#template").hide(); //隐藏模板
            ChangeState(0, 1); //设置翻页按钮的初始状态

            bind(); //绑定第一页的数据

            //第一页按钮click事件
            $("#first").click(function() {
                pageIndex = 1;
                ChangeState(0, 1);
                bind();
            });

            //上一页按钮click事件
            $("#previous").click(function() {
                pageIndex -= 1;
                ChangeState(-1, 1);
                if (pageIndex <= 1) {
                    pageIndex = 1;
                    ChangeState(0, -1);
                }
                bind();
            });

            //下一页按钮click事件
            $("#next").click(function() {
                pageIndex += 1;
                ChangeState(1, -1);
                if (pageIndex >= pageCount) {
                    pageIndex = pageCount;
                    ChangeState(-1, 0);
                }
                bind(pageIndex);
            });

            //最后一页按钮click事件
            $("#last").click(function() {
                pageIndex = pageCount;
                ChangeState(1, 0);
                bind(pageIndex);
            });
        });
        //设置第几页/共几页的信息
        function SetPageInfo() {
            $("#pageinfo").html(pageIndex + "/" + pageCount);
        }

        //AJAX方法取得分页总数
        function GetPageCount() {
            $.ajax({
                type: "get",
                dataType: "text",
                url: '/Ashx/Comments.ashx?action=getlist&ProductID=<%=ProductID%>' + '&temp=' + Math.random(),
                data: "getPageCount=1",
                async: false,
                success: function(msg) {
                    $("#pagecount").val(msg);
                }
            });
        }

        //改变翻页按钮状态    
        function ChangeState(state1, state2) {
            if (state1 == 1) {
                document.getElementById("first").disabled = "";
                document.getElementById("previous").disabled = "";
            }
            else if (state1 == 0) {
                document.getElementById("first").disabled = "disabled";
                document.getElementById("previous").disabled = "disabled";
            }
            if (state2 == 1) {
                document.getElementById("next").disabled = "";
                document.getElementById("last").disabled = "";
            }
            else if (state2 == 0) {
                document.getElementById("next").disabled = "disabled";
                document.getElementById("last").disabled = "disabled";
            }
        }



        function bind() {
            $.getJSON('/Ashx/Comments.ashx?action=getlist&ProductID=<%=ProductID%>&pageIndex=' + pageIndex + '&temp=' + Math.random(),
            function(comments) {
                var str = '';
                $.each(comments, function(i, item) {
                    str += '<ul>';
                    str += '<h4>';
                    if(<%=LanguageID%>==1){//中文
                        str += '<span><%=GetLangString("User")%>:' + item.Creator + '</span>';
                    }else{
                        if (item.Creator == "未注册") {
                            str += '<span><%=GetLangString("User")%>:Un Register</span>';
                        } else {
                            str += '<span><%=GetLangString("User")%>:' + item.Creator + '</span>';
                        }
                    }
                    str += '<%=GetLangString("Time")%>:' + item.CreateTime + '';
                    str += '</h4><h5>留言内容：</h5>';
                    
                    str += '<li>'+item.Content;+'</li>';
                    str += '</ul>';
                }
                );

                $("#Msgcontent").html(str);
                SetPageInfo();
            });
            
           
        }


        function addcomment() {
            var comment = document.getElementById('txtConmmet').value;
            if (comment == '') {
                return false;
            }
            $.ajax({
                url: '/Ashx/Comments.ashx?action=add',
                data: { 'content': comment, 'productid': '<%=ProductID%>' },
                type: 'post',
                timeout: 8000,
                cache: false,
                error: function() {
                    alert('<%=GetLangString("Error")%>');
                },
                success: function(html) {
                    alert('<%=GetLangString("AddSuccessful")%>');
                    GetPageCount(); //取得分页总数
                    pageCount = parseInt($("#pagecount").val()); //分页总数放到变量pageCount里
                    bind();
                    $("#txtConmmet").val("");
                }
            });

        }

    </script>
    <div class="company_news common_border">
        <div class="help_box">
            <h1>
                <%=GetLangString("ProductInfo")%></h1>
            <%--<ul class="common_page">
                <b>
                    <%=parentLink%></b>
            </ul>--%>
    <div class="cpfl_weizhi common_border" runat="server" id="divdh">
</div>
            <div class="search_result_div">
                <ul class="search_resultL">
                    <a > 
                        <%--<img src="/Common/image/common/search_jgimg.gif" width="150" height="140" alt="" />--%> 
                     <img src="<%=ProductInfoUrl %>" width="150" height="140" alt="" />
               </a> 
                </ul>
                <ul class="search_resultR">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td>
                                <b><%=description.Name%>&nbsp;&nbsp;&nbsp;<%=product.ItemCode %></b>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <%=GetLangString("BasicPrice")%>：
                                <%if(!GetProductBasePrice(ProductID).Price.Equals(0)){ %>
                                <span>
                                <%=GetProductBasePrice(product.ProductID).Price.ToString()%><%=GetProductBasePrice(product.ProductID).Currency%></span>
                                <span>(<%=GetLangString("NoTax")%>)</span>&nbsp;&nbsp;
                                <%}else{ %>
                                <%=GetLangString("Price0Desc")%> 
                                <%} %>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <%=GetLangString("ShopNumber")%>：<asp:TextBox ID="txtNumber" runat="server" onkeydown="return testKeyEven(event);"></asp:TextBox>(<%=SetInventoryString(product.InvQty)%>)
                            </td>
                        </tr>
                        <tr>
                            <td>
                                
                                <% if (LanguageID == 1)
                                {%>
                                <asp:ImageButton ID="btnAddToShoppingCart" BorderWidth="0" ImageUrl="/Common/image/common/goumai_btn.gif"
                                    runat="server" OnClick="btnAddToShoppingCart_Click" />
                                &nbsp;
                                <asp:ImageButton ID="btnFavorite" BorderWidth="0" ImageUrl="/Common/image/common/search_sc.gif"
                                    runat="server" OnClick="btnFavorite_Click" />
                                    <%}
                                else { 
                                %>
                                <asp:ImageButton ID="ImageButton1" BorderWidth="0" ImageUrl="/Common/image/common/goumai_btn.gif"
                                    runat="server" OnClick="btnAddToShoppingCart_Click" />
                                &nbsp;
                                <asp:ImageButton ID="ImageButton2" BorderWidth="0" ImageUrl="/Common/image/common/search_sc.gif"
                                    runat="server" OnClick="btnFavorite_Click" />
                                <%} %>
                            </td>
                        </tr>
                    </table>
                </ul>
            </div>
            <ul class="help_box_top">
                <li class="help_box_topon" id="cp1"><%=GetLangString("ProductInfo")%></li>
                <li id="cp2"><%=GetLangString("RelatedDownloads")%></li>
                <li id="cp3"><%=GetLangString("DetailComments")%></li>
                <li id="cp4"><%=GetLangString("RelatedProduct")%></li>
            </ul>
            <ul class="product_ul">
                <div class="product_cpxx" id="scp1">
                    <ul>
                        <h2>
                            <%=GetLangString("ProductInfo")%></h2>
                        <p>
                            <%=GetLangString("ItemCode")%>：<%=product.ItemCode%>
                        </p>
                        <p>
                            <%=GetLangString("ProductName")%>：<%=description.Name %>
                        </p>
                        <p>
                            <%=GetLangString("BrandName")%>：<%=GetBrandName(product.BrandID.Value)%>
                        </p>
                        <p>
                            <%=GetLangString("ShowIvq")%>：<%=SetInventoryString(product.InvQty)%>
                        </p>
                        <!--是否显示促销价-->
                        <% if (product.IsPromote && product.PromoteFrom < DateTime.Now && product.PromoteTo > DateTime.Now)
                        {%>
                        <p><%=GetLangString("PromoteDiscount")%>：<%=(Decimal.Round(Decimal.Parse(product.PromoteDiscount.ToString()),2)*100).ToString() +"%"%></p>
                        <%} %>
                        <p><%=GetLangString("TaxRate")%>：<%=product.TaxRate %></p>
                        <p>
                        <p><%=GetLangString("ShipDays")%>：<%=product.ShipDays %></p>
                        <p><%=GetLangString("MinMultiple")%>：<%=product.MinMultiple%></p>
                        <p><%=GetLangString("MinNumber")%>：<%=product.MinNumber%></p>
                        <p>
                            <%=GetLangString("Weight")%>：<%=product.Weight%><%=product.WeightUnit.ToString().ToUpper() %>
                        </p>
                        <p style="line-height:18px;">
                            <%=GetLangString("Description")%>：<%=checkStr(description.Description)%>
                        </p>
                    </ul>
                    <ul>
                        <h2>
                            <%=GetLangString("DetailSpecs")%></h2>
                    </ul>
                </div>
                <div id="scp3" class="product_pjxq">
                    <ul class="product_pjxq_top">
                        <li>
                            <textarea id="txtConmmet" cols="40" rows="4"></textarea>
                        </li>
                        <li>
                            <input type="button" onclick="addcomment()" value='<%=GetLangString("AddComments") %>' />
                        </li>
                    </ul>
                    <div class="message">
                        <h2>留言列表</h2>
                            <div id="Msgcontent">
                            <!--循环体-->
                            <!--循环体end-->    
                            </div>
                    </div>
                    <div style="width:100%;text-align:center;">
                    <!--分页控件-->
                        <input id="first" type="button"  style="background: url('/images/gray.gif'); height: 21px; width: 60px;border: 0px; color: White"  value="<%=GetLangString("BtnIndex") %>"/>
                             <input id="previous" type="button" style="background: url('/images/gray.gif'); height: 21px; width: 60px;border: 0px; color: White"  value="<%=GetLangString("BtnPrevious") %>"/>
                             <input id="next" type="button" style="background: url('/images/gray.gif'); height: 21px; width: 60px; border: 0px; color: White"  value="<%=GetLangString("BtnNext") %>"/>
                             <input id="last" type="button" style="background: url('/images/gray.gif'); height: 21px; width: 60px; border: 0px; color: White"   value="<%=GetLangString("BtnLast") %>"/>
                        &nbsp;<span id="pageinfo"></span>
                    </div>
                    <ul class="fenyetwo floatright">
                    </ul>
                </div>
                <div class="car_table" id="scp2" style="display: none;">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <th scope="col">
                                <%=GetLangString("FileName") %>
                            </th>
                            <th scope="col">
                                描述
                            </th>
                            <th scope="col">
                                <%=GetLangString("FileSize")%>
                            </th>
                            <th scope="col">
                                <%=GetLangString("Download")%>
                            </th>
                        </tr>
                        <asp:Repeater ID="repResource" runat="server" OnItemCommand="repResource_ItemCommand">
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <%#Eval("FileName") %>
                                    </td>
                                    <td>
                                        
                                    </td>
                                    <td>
                                        <%#Eval("FileSize") %>
                                    </td>
                                    <td>
                                        <asp:Button ID="btDown"  style="background :url('/images/gray.gif');height:21px;width:60px;border:0px;  color:White"      CommandArgument='<%#Eval("FileName") %>' CommandName="Down" Text='<%#Eval("DownLoad") %>' runat="server" ></asp:Button>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </table>
                </div>
                <div class="product_xgcp" id="scp4">
                    <asp:DataList ID="dlCategory" runat="server" RepeatColumns="4">
                        <ItemTemplate>
                            <ul class="apply_box_ul">
                                <h1>
                                    <%#Eval("CategoryName")%></h1>
                                <h2>
                                    <a href='<%# string.Format("Category.aspx?cid={0}", Eval("CategoryID")) %>'>
                                        <img src="<%#pcm.GetCategoryImage(int.Parse(Eval("CategoryID").ToString()))%>" width="150" height="150" /></a></h2>
                                <p>
                                    <a href='<%# string.Format("Category.aspx?cid={0}", Eval("CategoryID")) %>'>
                                        <%#returnName(Eval("CategoryName").ToString())%>
                                    </a>
                                </p>
                            </ul>
                        </ItemTemplate>
                    </asp:DataList>
                </div>
            </ul>
        </div>
        <input id="pagecount" type="hidden" />
    </div>
    </form>
</asp:Content>
